<template>
	<uni-card :is-shadow="false" is-full>
		<text class="uni-h6">呼叫转拨插件演示demo</text>
	</uni-card>
	<uni-section title="参数" type="line" padding>
		<uni-easyinput v-model="phone" placeholder="设置转拨的号码"></uni-easyinput>
	</uni-section>
	<uni-section title="返回信息" type="line" padding>
		<view class="">
			{{msg}}
		</view>
	</uni-section>
	<uni-section title="操作" type="line">
		<button @click="savePhone" type="primary" class="uni-mt-2 uni-mx-2">保存号码</button>
		<button @click="cancelSetting" type="primary" class="uni-mt-2 uni-mx-2">取消转拨</button>
	</uni-section>
	
</template>

<script>
	export default {
		data() {
			return {
				TAG: 'Huo15TelecomModule',
				phone:'15288986891',
				huo15Sdk:null,
				msg:'',
			}
		},
		onLoad() {
			this.huo15Sdk = uni.requireNativePlugin('Huo15-Telecom')
			const globalEvent = uni.requireNativePlugin('globalEvent')
			console.log(this.huo15Sdk)	
			this.huo15Sdk.requestPermissions()
			
			globalEvent.addEventListener('huo15_notify', (e) => {
				console.log(JSON.stringify(e))
			})
			globalEvent.addEventListener('huo15_tel', (e) => {
				console.log(JSON.stringify(e))
				this.msg=this.msg+`${new Date()}您拨打的电话是: ${e.tel}|`;
				uni.showToast({
					title:'拨打的电话是：'+e.tel,
					icon:'none'
				})
			})
			
		},
		methods: {
			savePhone(){
				console.log('savePhone');
				this.huo15Sdk.savePhone({phone:this.phone},res=>{
					if(res.code==0){
						console.log("配置成功：",e.msg);
					}else {
						console.log("配置失败：",e.msg);
					}
				})
			},
			cancelSetting(){
				console.log('cancelSetting');
				this.huo15Sdk.cancelSetting()
			},
		}
	}
</script>

<style>

</style>
